package chap2

object Chap2 {
  def signum(n: Int)= {
    if (n<0) -1 else if(n == 0) n else 1
  } 
  
 def countDown(n:Int){
   var num = n
   while(num>0){
     println(num)
     num -=  1
   }
 } 

 def unif(str: String): Int= {
   var sum = 1
   for(c  <-  str) sum *= c
   sum
 }
 
 def unistr(str: String): Int = {
   var sum = 1
   str.foreach (sum *=_.toInt)
   sum
 }
 
 def product(str: String): Int = {
   var sum = 1
   str.foreach (sum *=_.toInt)
   sum
 }
 
 def digui(str: String): Int= {
//   println(str.drop(0))
   if (str.length() ==1 ) str(0).toInt;
   else str(0).toInt * digui(str.drop(1))

 }
 
 def powx(x: Int,n: Int): Int = {
   if (0 == n) 1
   else if (n > 0 && n%2 ==0)  powx(x,n/2) *  powx(x,n/2)
   else if (n > 0 && n%2 !=0 ) x * powx(x,n-1)
   else 1 / powx(x,-n)
 }
 
  def main(args: Array[String]): Unit = {
    println(signum(-3))
    println(signum(3))
    println(signum(0))
    countDown(5)
    println(unif("Hello"))
    println(unistr("Hello"))
    println(digui("Hello"))
    println(powx(-2,5));
  }
}
